//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "RectangularDomain.h"
using namespace Cephei::QL::Math;
#include <gen/QL/Math/BoundedDomain.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::CRectangularDomain::CRectangularDomain (Double x1, Double y1, Double x2, Double y2) : CBoundedDomain(CRectangularDomain::typeid)
{
    try
    {
#ifdef HANDLE
        _phRectangularDomain = NULL;
#endif
        QuantLib::Real _x1 = (QuantLib::Real)ValueHelper::Convert (x1);
        QuantLib::Real _y1 = (QuantLib::Real)ValueHelper::Convert (y1);
        QuantLib::Real _x2 = (QuantLib::Real)ValueHelper::Convert (x2);
        QuantLib::Real _y2 = (QuantLib::Real)ValueHelper::Convert (y2);
        _ppRectangularDomain = new boost::shared_ptr<QuantLib::RectangularDomain> (new QuantLib::RectangularDomain ( _x1,  _y1,  _x2,  _y2 ));
        SetBoundedDomain (boost::dynamic_pointer_cast<QuantLib::BoundedDomain> (*_ppRectangularDomain));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::CRectangularDomain::CRectangularDomain (boost::shared_ptr<QuantLib::RectangularDomain>& childNative, Object^ owner) : CBoundedDomain(CRectangularDomain::typeid)
{
#ifdef HANDLE
	_phRectangularDomain = NULL;
#endif
	_ppRectangularDomain = &childNative;
    _ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (boost::dynamic_pointer_cast<QuantLib::BoundedDomain> (*_ppRectangularDomain));
}
Cephei::QL::Math::CRectangularDomain::CRectangularDomain (QuantLib::RectangularDomain& childNative, Object^ owner) : CBoundedDomain(CRectangularDomain::typeid)
{
#ifdef HANDLE
	_phRectangularDomain = NULL;
#endif
	_ppRectangularDomain = new boost::shared_ptr<QuantLib::RectangularDomain> (&childNative);
    _ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (boost::dynamic_pointer_cast<QuantLib::BoundedDomain> (*_ppRectangularDomain));
    _RectangularDomainOwner = owner;
    _BoundedDomainOwner = owner;
}

Cephei::QL::Math::CRectangularDomain::CRectangularDomain (CRectangularDomain^ copy) : CBoundedDomain(CRectangularDomain::typeid)
{
#ifdef HANDLE
	_phRectangularDomain = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppRectangularDomain = new boost::shared_ptr<QuantLib::RectangularDomain> (copy->GetShared());
        _ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (boost::dynamic_pointer_cast<QuantLib::BoundedDomain> (*_ppRectangularDomain));
    }
}
Cephei::QL::Math::CRectangularDomain::CRectangularDomain (System::Type^ t) : CBoundedDomain(CRectangularDomain::typeid)
{
#ifdef HANDLE
	_phRectangularDomain = NULL;
#endif
	if (!t->IsSubclassOf(CRectangularDomain::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::CRectangularDomain::CRectangularDomain (QuantLib::Handle<QuantLib::RectangularDomain>& childNative, Object^ owner)  : CBoundedDomain(CRectangularDomain::typeid)
{
	_phRectangularDomain = &childNative;
	_ppRectangularDomain = &static_cast<boost::shared_ptr<QuantLib::RectangularDomain>>(childNative.currentLink());
    _ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (boost::dynamic_pointer_cast<QuantLib::BoundedDomain> (*_ppRectangularDomain));
    _RectangularDomainOwner = owner;
}
Cephei::QL::Math::CRectangularDomain::CRectangularDomain (QuantLib::Handle<QuantLib::RectangularDomain> childNative)  : CBoundedDomain(CRectangularDomain::typeid)
{
	_phRectangularDomain = &childNative;
	_ppRectangularDomain = &static_cast<boost::shared_ptr<QuantLib::RectangularDomain>>(childNative.currentLink());
    _ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (boost::dynamic_pointer_cast<QuantLib::BoundedDomain> (*_ppRectangularDomain));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::CRectangularDomain::CRectangularDomain (QuantLib::RectangularDomain childNative)  : CBoundedDomain(CRectangularDomain::typeid)
{
#ifdef HANDLE
	_phRectangularDomain = NULL;
#endif
	_ppRectangularDomain = new boost::shared_ptr<QuantLib::RectangularDomain> (new QuantLib::RectangularDomain (childNative));
    _ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (boost::dynamic_pointer_cast<QuantLib::BoundedDomain> (*_ppRectangularDomain));
}
#endif

Cephei::QL::Math::CRectangularDomain::~CRectangularDomain ()
{
    if (_ppRectangularDomain != NULL)
    {
	    delete _ppRectangularDomain;
        _ppRectangularDomain = NULL;
    }
}
Cephei::QL::Math::CRectangularDomain::!CRectangularDomain ()
{
    if (_ppRectangularDomain != NULL)
    {
	    delete _ppRectangularDomain;
    }
}
QuantLib::RectangularDomain& Cephei::QL::Math::CRectangularDomain::GetReference ()
{
    if (_ppRectangularDomain == NULL) throw gcnew NativeNullException ();
	return **_ppRectangularDomain;
}
boost::shared_ptr<QuantLib::RectangularDomain>& Cephei::QL::Math::CRectangularDomain::GetShared ()
{
    if (_ppRectangularDomain == NULL) throw gcnew NativeNullException ();
	return *_ppRectangularDomain;
}
QuantLib::RectangularDomain* Cephei::QL::Math::CRectangularDomain::GetPointer ()
{
    if (_ppRectangularDomain == NULL) throw gcnew NativeNullException ();
	return &**_ppRectangularDomain;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::RectangularDomain>& Cephei::QL::Math::CRectangularDomain::GetHandle ()
{
	if (_phRectangularDomain == NULL)
	{
		_phRectangularDomain = new Handle<QuantLib::RectangularDomain> (*_ppRectangularDomain);
	}
	return *_phRectangularDomain;
}
#endif
bool Cephei::QL::Math::CRectangularDomain::HasNative () 
{
	return (_ppRectangularDomain != NULL);
}

Boolean Cephei::QL::Math::CRectangularDomain::Includes (Double x, Double y)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x);
        QuantLib::Real _y = (QuantLib::Real)ValueHelper::Convert (y);
    	bool _rv = (bool)(*_ppRectangularDomain)->includes ( _x,  _y );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::CRectangularDomain::XLowerBound::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppRectangularDomain)->xLowerBound ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::CRectangularDomain::XUpperBound::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppRectangularDomain)->xUpperBound ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::CRectangularDomain::YLowerBound::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppRectangularDomain)->yLowerBound ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::CRectangularDomain::YUpperBound::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppRectangularDomain)->yUpperBound ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::IRectangularDomain^ Cephei::QL::Math::CRectangularDomain_Factory::Create (Double x1, Double y1, Double x2, Double y2)
{
    return gcnew CRectangularDomain ( x1,  y1,  x2,  y2);
}
